package db.formulation;

import java.util.Map;

import db.AbstractService;
import db.fortifier.Fortifier;
import db.fortifier.FortifierService;
import db.vector.Vector;
import db.vector.VectorService;

public class FormulationService extends AbstractService<Formulation> implements FormulationDAO
{
    private FortifierService fortifierService;
    private VectorService vectorService;
    
    public void setFortifierService(FortifierService fortifierService) {
        this.fortifierService = fortifierService;
    }
    
    public void setVectorService(VectorService vectorService) {
        this.vectorService = vectorService;
    }
    
    // more DAOs
    public Map<Fortifier, Double> listFortifier(Long formulationId) {
        Formulation formulation = find(formulationId);
        return formulation.getFortifiers();
    }
    
    public void addFortifier(Long formulationId, Long fortifierId, Double mass) {
        Fortifier fortifier = fortifierService.find(fortifierId);
        Formulation formulation = find(formulationId);
        formulation.getFortifiers().put(fortifier, mass);
        insert(formulation);
    }
    
    public void setVector(Long formulationId, Long vectorId) {
        Vector vector = vectorService.find(vectorId);
        Formulation formulation = find(formulationId);
        formulation.setVector(vector);
        insert(formulation);
    }
    
    public void newFormulation(String name, Long vectorId, Long fortifierId, Double mass) {
        Formulation formulation = new Formulation();
        formulation.setName(name);
        Vector vector = vectorService.find(vectorId);
        formulation.setVector(vector);
        Fortifier fortifier = fortifierService.find(fortifierId);
        formulation.getFortifiers().put(fortifier, mass);
        insert(formulation);
    }
}
